﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WHW_NetUtility
{
    class DataGridViewOpe
    {

        public static bool RowColor(DataGridView dgv, System.Drawing.Color oddcolor,System.Drawing.Color evencolor)
        {
            //ColorDialog  //颜色选择对话框
            return true;
        }
        /// <summary>
        /// 按行添加listview数据(添加到尾部)
        /// </summary>
        /// <param name="dgv">DataGridView控件名称</param>
        /// <param name="context">要添加到DataGridView控件中的行数据数组，不添加内容的列，字符串为空</param>
        /// <returns>添加成功返回true，否则返回false</returns>
        public static bool Add(DataGridView dgv, string[] context)
        {
            try
            {
                //dgv.SelectionMode = DataGridViewSelectionMode.CellSelect;
                int count=0;
                //dgv.BeginUpdate();

                //if (dgv.Rows.Count == 1)
                //{
                //    string m = dgv.Rows[dgv.Rows.Count - 1].Cells[0].Value.ToString();
                //    if (string.IsNullOrEmpty(dgv.Rows[dgv.Rows.Count - 1].Cells[0].Value.ToString()) || dgv.Rows[dgv.Rows.Count - 1].Cells[0] == null)
                //    {
                //        count = 0;
                //    }
                //    else
                //    {
                //        count = dgv.Rows.Add();
                //    }
                //}

                count = dgv.Rows.Add();
                dgv.Rows[count].Cells[0].Value = (count + 1).ToString();
                for (int i=0;i<context.Length;i++)
                {
                    dgv.Rows[count].Cells[i+1].Value=context[i].ToString();
                }
                //dgv.Rows[dgv.Rows.Count - 1].Selected = true;
                //dgv.CurrentCell = dgv[1, count];
                //dgv.BindingContext[dgv.DataSource].Position = count;
                //lv.EndUpdate();
                //dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                return true;
            }
            catch (System.Exception ex)
            {
                Log4Helper.WriteLog("DataGridViewOpe.Add", ex);
                return false;
            }
        }
    }
}
